function [fb_av,pb_av,vis_mean,run_mean,blink_mean,eye_mean,ffm_mean,fdbk_mean]=meta_analysis_get_info(proj_meta,cur_site,cells)

order={};
exp_inds={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    nbr_frames=proj_meta(cur_site).rd(1,tnd).nbr_frames;
    if length(nbr_frames)>5
        for xnd=1:length(nbr_frames)
            if nbr_frames(xnd)==5000
                if xnd==length(nbr_frames)
                    order{tnd}(xnd)=3;
                else
                    order{tnd}(xnd)=1;
                end
            else
                order{tnd}(xnd)=2;
            end
        end
        ord_ind=1:length(order{tnd});
        order{tnd}(max(ord_ind(order{tnd}==2))+1:end)=3;
    else
        order{tnd}=[1 2 1 2 3];
    end
    exp_inds{tnd}(1,1)=1;
    exp_inds{tnd}(1,2)=nbr_frames(1);
    for fnd=2:length(order{tnd})
        exp_inds{tnd}(fnd,1)=exp_inds{tnd}(fnd-1,2)+1;
        exp_inds{tnd}(fnd,2)=sum(nbr_frames(1:fnd));
    end
end

shad_all={};
vis_fl_all={};
delta_all={};
pert_num={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    cur_pert_num=[];
    ps_id=proj_meta(cur_site).rd(1,tnd).ps_id;
    runM=proj_meta(cur_site).rd(1,tnd).velM_smoothed>0.01;
    runP=proj_meta(cur_site).rd(1,tnd).velP_smoothed>0.01;
    pupil_pos=proj_meta(cur_site).rd(1,tnd).pupil_pos;
    shad=[];
    vis_fl=[];
    cnt=1;
    for bnd=1:length(order{tnd})
        if order{tnd}(bnd)==1
            tmp_runM=runM(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_ps_id=ps_id(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            for fnd=1:length(tmp_runM)
                if tmp_runM(fnd)==0
                    shad(cnt)=0;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif tmp_runM(fnd)==1 & logical(tmp_ps_id(fnd))==0 %feedback
                    shad(cnt)=1;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif tmp_runM(fnd)==1 & logical(tmp_ps_id(fnd))==1 %feedback mismatch
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=3;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
                        shad(cnt)=4;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                end
            end
        elseif order{tnd}(bnd)==2
            tmp_runM=runM(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_ps_id=ps_id(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_runP=runP(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            for fnd=1:length(tmp_runM)
                if logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0 | logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0
                    shad(cnt)=0;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=5;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
                        shad(cnt)=6;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                    shad(cnt)=2;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                    shad(cnt)=1;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0 | logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0
                    shad(cnt)=3;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=3;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
                        shad(cnt)=4;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                end
            end
        end
    end
    shad_all{tnd}=shad;
    vis_fl(length(vis_fl):length(runM))=0;
    vis_fl_all{tnd}=vis_fl;
    delta=sqrt(diff(pupil_pos(1,:)).^2+diff(pupil_pos(2,:)).^2);
    delta(end+1)=delta(end);
    delta_all{tnd}=delta;
    pert_num{tnd}=cur_pert_num;
end

all_act={};
pl_cells=[];
mean_fluo=[];
for tnd=1:size(proj_meta(cur_site).rd,2)
    cnt=0;
    for vnd=1:size(proj_meta(cur_site).rd,1)
        all_act{tnd}(cnt+1:cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1),:)=proj_meta(cur_site).rd(vnd,tnd).act;
        mean_fluo(cnt+1:cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1),tnd)=mean(proj_meta(cur_site).rd(vnd,tnd).act,2);
        cnt=cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1);
        pl_cells(vnd)=cnt;
    end
end

names{1}='feedback';
names{2}='playback';
names{3}='feedback.FFM';
names{4}='feedback.LFM';
names{5}='playback.FFM';
names{6}='playback.LFM';

col{1}=[0.8 0.8 0.8];
col{2}=[0.3 0.7 0.3];
col{3}=[1 0.5 0];
col{4}=[1 1 0.5];
col{5}=[0.9 0.2 0.2];
col{6}=[0 1 1];

pert_id={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    cur_ons=find(diff(pert_num{tnd})>0|diff(pert_num{tnd})<0);
    cur_ons=cur_ons+1;
    cur_pert=pert_num{tnd}(cur_ons);
    zeros_ind=find(cur_pert==0);
    cur_ons(zeros_ind)=[];
    cur_pert(zeros_ind)=[];
    pert_id{tnd}=[cur_ons;cur_pert];
end

fb_snip={};
pb_snip={};
fb_av={};
pb_av={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    nbr_frames=proj_meta(cur_site).rd(1,tnd).nbr_frames;
    stim_id=proj_meta(cur_site).rd(1,tnd).ps_id;
    runP=proj_meta(cur_site).rd(1,tnd).velP_smoothed>0.01;
    runM=proj_meta(cur_site).rd(1,tnd).velM_smoothed>0.01;
    runM_raw=proj_meta(cur_site).rd(1,tnd).velM_smoothed;
    if nargin==3
        for lnd=1:length(cells)
            act=all_act{tnd}(cells(lnd),:);
            [fb_av{lnd,tnd},pb_av{lnd,tnd},fb_snip{lnd,tnd},pb_snip{lnd,tnd}]=pert_ana_meta(nbr_frames,stim_id,runM,runP,runM_raw,act);
        end
    else
        for lnd=1:size(all_act{1},1)
            act=all_act{tnd}(lnd,:);
            [fb_av{lnd,tnd},pb_av{lnd,tnd},fb_snip{lnd,tnd},pb_snip{lnd,tnd}]=pert_ana_meta(nbr_frames,stim_id,runM,runP,runM_raw,act);
        end
    end
end

[vis_snips,run_snips,ffm_snips,fdbk_snips]=meta_analysis_find_onset_snips(proj_meta,cur_site,vis_fl_all,order,exp_inds,shad_all);
[blink_snips,eye_snips]=meta_analysis_eye_onset(proj_meta,cur_site,delta_all);

vis_resp={};
vis_mean={};
run_resp={};
run_mean={};
blink_resp={};
blink_mean={};
eye_resp={};
eye_mean={};
ffm_resp={};
ffm_mean={};

vis_sig={};
run_sig={};
blink_sig={};
eye_sig={};
ffm_sig={};

fdbk_resp={};
fdbk_mean={};
fdbk_sig={};

if nargin==3
    for ind=1:length(cells)
        for tnd=1:size(proj_meta(cur_site).rd,2)
            cur_act=all_act{tnd}(cells(ind),:);
            for hnd=1:size(vis_snips{tnd},1)
                vis_resp{ind,tnd}(hnd,:)=cur_act(vis_snips{tnd}(hnd,1):vis_snips{tnd}(hnd,2));
            end
            vis_mean{tnd}(ind,:)=mean(vis_resp{ind,tnd},1);
            vis_sig{ind,tnd}=vis_resp{ind,tnd}(sum(vis_resp{ind,tnd}(:,1:3),2)*1.1<sum(vis_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(run_snips{tnd},1)
                run_resp{ind,tnd}(hnd,:)=cur_act(run_snips{tnd}(hnd,1):run_snips{tnd}(hnd,2));
            end
            run_mean{tnd}(ind,:)=mean(run_resp{ind,tnd},1);
            run_sig{ind,tnd}=run_resp{ind,tnd}(sum(run_resp{ind,tnd}(:,1:3),2)*1.1<sum(run_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(blink_snips{tnd},1)
                blink_resp{ind,tnd}(hnd,:)=cur_act(blink_snips{tnd}(hnd,1):blink_snips{tnd}(hnd,2));
            end
            blink_mean{tnd}(ind,:)=mean(blink_resp{ind,tnd},1);
            blink_sig{ind,tnd}=blink_resp{ind,tnd}(sum(blink_resp{ind,tnd}(:,1:3),2)*1.1<sum(blink_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(eye_snips{tnd},1)
                eye_resp{ind,tnd}(hnd,:)=cur_act(eye_snips{tnd}(hnd,1):eye_snips{tnd}(hnd,2));
            end
            eye_mean{tnd}(ind,:)=mean(eye_resp{ind,tnd},1);
            eye_sig{ind,tnd}=eye_resp{ind,tnd}(sum(eye_resp{ind,tnd}(:,1:3),2)*1.1<sum(eye_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(ffm_snips{tnd},1)
                ffm_resp{ind,tnd}(hnd,:)=cur_act(ffm_snips{tnd}(hnd,1):ffm_snips{tnd}(hnd,2));
            end
            ffm_mean{tnd}(ind,:)=mean(ffm_resp{ind,tnd},1);
            ffm_sig{ind,tnd}=ffm_resp{ind,tnd}(sum(ffm_resp{ind,tnd}(:,1:3),2)*1.1<sum(ffm_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(fdbk_snips{tnd},1)
                fdbk_resp{ind,tnd}(hnd,:)=cur_act(fdbk_snips{tnd}(hnd,1):fdbk_snips{tnd}(hnd,2));
            end
            fdbk_mean{tnd}(ind,:)=mean(fdbk_resp{ind,tnd},1);
            fdbk_sig{ind,tnd}=fdbk_resp{ind,tnd}(sum(fdbk_resp{ind,tnd}(:,1:3),2)*1.1<sum(fdbk_resp{ind,tnd}(:,end-2:end),2),:);
        end
    end
else
    for ind=1:size(all_act{1},1)
        for tnd=1:size(proj_meta(cur_site).rd,2)
            cur_act=all_act{tnd}(ind,:);
            for hnd=1:size(vis_snips{tnd},1)
                vis_resp{ind,tnd}(hnd,:)=cur_act(vis_snips{tnd}(hnd,1):vis_snips{tnd}(hnd,2));
            end
            vis_mean{tnd}(ind,:)=mean(vis_resp{ind,tnd},1);
            vis_sig{ind,tnd}=vis_resp{ind,tnd}(sum(vis_resp{ind,tnd}(:,1:3),2)*1.1<sum(vis_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(run_snips{tnd},1)
                run_resp{ind,tnd}(hnd,:)=cur_act(run_snips{tnd}(hnd,1):run_snips{tnd}(hnd,2));
            end
            run_mean{tnd}(ind,:)=mean(run_resp{ind,tnd},1);
            run_sig{ind,tnd}=run_resp{ind,tnd}(sum(run_resp{ind,tnd}(:,1:3),2)*1.1<sum(run_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(blink_snips{tnd},1)
                blink_resp{ind,tnd}(hnd,:)=cur_act(blink_snips{tnd}(hnd,1):blink_snips{tnd}(hnd,2));
            end
            blink_mean{tnd}(ind,:)=mean(blink_resp{ind,tnd},1);
            blink_sig{ind,tnd}=blink_resp{ind,tnd}(sum(blink_resp{ind,tnd}(:,1:3),2)*1.1<sum(blink_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(eye_snips{tnd},1)
                eye_resp{ind,tnd}(hnd,:)=cur_act(eye_snips{tnd}(hnd,1):eye_snips{tnd}(hnd,2));
            end
            eye_mean{tnd}(ind,:)=mean(eye_resp{ind,tnd},1);
            eye_sig{ind,tnd}=eye_resp{ind,tnd}(sum(eye_resp{ind,tnd}(:,1:3),2)*1.1<sum(eye_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(ffm_snips{tnd},1)
                ffm_resp{ind,tnd}(hnd,:)=cur_act(ffm_snips{tnd}(hnd,1):ffm_snips{tnd}(hnd,2));
            end
            ffm_mean{tnd}(ind,:)=mean(ffm_resp{ind,tnd},1);
            ffm_sig{ind,tnd}=ffm_resp{ind,tnd}(sum(ffm_resp{ind,tnd}(:,1:3),2)*1.1<sum(ffm_resp{ind,tnd}(:,end-2:end),2),:);
            for hnd=1:size(fdbk_snips{tnd},1)
                fdbk_resp{ind,tnd}(hnd,:)=cur_act(fdbk_snips{tnd}(hnd,1):fdbk_snips{tnd}(hnd,2));
            end
            fdbk_mean{tnd}(ind,:)=mean(fdbk_resp{ind,tnd},1);
            fdbk_sig{ind,tnd}=fdbk_resp{ind,tnd}(sum(fdbk_resp{ind,tnd}(:,1:3),2)*1.1<sum(fdbk_resp{ind,tnd}(:,end-2:end),2),:);
        end
    end
end